package com.ll.xiaonew.system.modules.homes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ll.xiaonew.commons.core.utils.PageUtils;
import com.ll.xiaonew.commons.core.utils.Query;
import com.ll.xiaonew.system.modules.homes.dao.HomePictureDao;
import com.ll.xiaonew.system.modules.homes.entity.HomePictureEntity;
import com.ll.xiaonew.system.modules.homes.service.HomePictureService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("homePictureService")
public class HomePictureServiceImpl extends ServiceImpl<HomePictureDao, HomePictureEntity> implements HomePictureService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<HomePictureEntity> page = this.page(
                new Query<HomePictureEntity>().getPage(params),
                new QueryWrapper<HomePictureEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List findPictureList() {
        //先查询有没有当天展示的图片
        List curlist = baseMapper.findCurrentToday();

        //判断是否有当天需要展示的图片,没有展示上一张图片
        if (curlist==null||curlist.size()==0) {
            curlist = baseMapper.findCurrentLast();
        }
        return curlist;
    }

}